<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:p="http://primefaces.prime.com.tr/ui">
		<h:form id="idInstituicaoMBForm">
			<p:panel>
				<p:messages globalOnly="true" rendered="true"/>
				<f:facet name="header">
					<h:outputText value="#{msg.instituicao}" />
				</f:facet>

				<fieldset id="legend_area"><legend id="legend"><h:outputLabel
					value="#{msg.instituicaoDados}" /></legend> 
					<h:panelGrid columns="4">
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.nome}" for="idNomeInst" />
						<span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idNomeInst" styleClass="mensagem_erro_campo" /><br/>
						<h:inputHidden value="#{instituicaoMB.instituicao.id}" />
						<h:inputText id="idNomeInst"
							value="#{instituicaoMB.instituicao.nome}" size="50"
							onkeyup="javascript:toUpperCase(this);" required="true"
							requiredMessage="#{msg.campoObrigatorio}">
							<rich:ajaxValidator event="onblur" />
						</h:inputText>
					</h:panelGroup>

					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.unidade}" for="idUnidadeInst" />
						<span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idUnidadeInst" styleClass="mensagem_erro_campo" /><br/>
						<h:inputText id="idUnidadeInst"
							value="#{instituicaoMB.instituicao.unidade}" size="50"
							onkeyup="javascript:toUpperCase(this);" required="true"
							requiredMessage="#{msg.campoObrigatorio}">
							<rich:ajaxValidator event="onblur" />
						</h:inputText>
					</h:panelGroup>
					
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.descricao}" for="idDescricaoInst" />
					</h:panelGroup>
					<h:panelGroup>
						<br/>
						<h:inputText id="idDescricaoInst"
							value="#{instituicaoMB.instituicao.descricao}" size="50"
							onkeyup="javascript:toUpperCase(this);">
						</h:inputText>
					</h:panelGroup>
					
					<h:panelGroup>
					</h:panelGroup>
					<h:panelGroup>
					</h:panelGroup>
				</h:panelGrid>
				
				<br/>
				<h:outputFormat value="#{msg.contato}" styleClass="label_bold"/>
				<h:panelGrid columns="4">
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.telefoneEmp}" for="idContatoInstEmp" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idContatoInstEmp" styleClass="mensagem_erro_campo"/><br/>
						<p:inputMask id="idContatoInstEmp" value="#{instituicaoMB.logradouro.telefoneEmpresa}" 
							required="true" requiredMessage="#{msg.campoObrigatorio}" size="16" mask="(99)9999-9999">
							<f:validator validatorId="checkfonevazio" />
							<rich:ajaxValidator event="onblur" />
						</p:inputMask>
					</h:panelGroup>
				
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.telefoneCel}" for="idContatoInstCel" />
					</h:panelGroup>
					<h:panelGroup>
						<br/>
						<p:inputMask id="idContatoInstCel" value="#{instituicaoMB.logradouro.telefoneCelular}" mask="(99)9999-9999" size="16">
						</p:inputMask>
					</h:panelGroup>
				
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.email}" for="idEmailInst" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<br/>
						<h:inputText id="idEmailInst" value="#{instituicaoMB.instituicao.email}" required="true" requiredMessage="#{msg.campoObrigatorio}" maxlength="45" size="45">
							<f:validator validatorId="checkemailinvalido" />
							<rich:ajaxValidator event="onblur" />
						</h:inputText> <rich:message for="idEmailInst" styleClass="mensagem_erro_campo"/>
					</h:panelGroup>					
				</h:panelGrid>					
				
				</fieldset>
				<fieldset id="legend_area">
				<legend id="legend"><h:outputLabel value="#{msg.enderecoDados}" /></legend> 
				<h:panelGrid columns="6" cellspacing="2">
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.rua}" for="idRuaInst" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idRuaInst" styleClass="mensagem_erro_campo" /><br/>
						<h:inputText id="idRuaInst"
							value="#{instituicaoMB.logradouro.rua}" size="50"
							onkeyup="javascript:toUpperCase(this);" required="true"
							requiredMessage="#{msg.campoObrigatorio}">
							<rich:ajaxValidator event="onblur" />
						</h:inputText>
					</h:panelGroup><h:panelGroup></h:panelGroup>
					
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.numeroLogradouro}" for="idNumeroInst" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idNumeroInst" styleClass="mensagem_erro_campo" /><br/>
						<p:inputMask id="idNumeroInst" mask="9999"
							value="#{instituicaoMB.logradouro.numero}" size="6" maxlength="5"
							onkeyup="javascript:toUpperCase(this);" required="true"
							requiredMessage="#{msg.campoObrigatorio}">
							<rich:ajaxValidator event="onblur" />
						</p:inputMask>
					</h:panelGroup><h:panelGroup></h:panelGroup>

					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.cep}" for="idCepInst" />
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idCepInst" styleClass="mensagem_erro_campo"/><br/>
						<h:inputText id="idCepInst" value="#{instituicaoMB.logradouro.cep}">
							<rich:jQuery  selector="#idCepInst" query="mask('99999-999')" timing="onload"/>
						</h:inputText>
					</h:panelGroup><h:panelGroup></h:panelGroup>
					
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.bairro}" for="idBairroInst" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idBairroInst" styleClass="mensagem_erro_campo"/><br/>
						<h:inputText id="idBairroInst" value="#{instituicaoMB.logradouro.bairro}"
							required="true" requiredMessage="#{msg.campoObrigatorio}" onkeyup="javascript:toUpperCase(this);">
							<rich:ajaxValidator event="onblur" />
						</h:inputText>	
					</h:panelGroup><h:panelGroup></h:panelGroup>
				
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.estado}" for="idUfInst" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
						<rich:message for="idUfInst" styleClass="mensagem_erro_campo"/><br/>
						<rich:comboBox id="idUfInst" defaultLabel="#{msg.escolhaOpcao}" width="50" value="#{instituicaoMB.logradouro.cidade.estado}"
							 valueChangeListener="#{logradouroMB.ufAlterado}" required="true" requiredMessage="#{msg.campoObrigatorio}">							 
							<f:selectItems value="#{logradouroMB.ufOpts}"/>
							<a4j:support event="onblur" reRender="idCidadeInst" ajaxSingle="true"/>
						</rich:comboBox>
					</h:panelGroup>
					<h:panelGroup>
						<br/>
						<h:outputLabel value="#{msg.cidade}" for="idCidadeInst" /><span class="req"> *</span>
					</h:panelGroup>
					<h:panelGroup>
					<rich:message for="idCidadeInst" styleClass="mensagem_erro_campo"/><br/>
					<rich:comboBox rendered="true" id="idCidadeInst" defaultLabel="#{msg.escolhaOpcao}" 
						width="200" value="#{instituicaoMB.logradouro.cidade.nome}" enableManualInput="false"
						required="true" requiredMessage="#{msg.campoObrigatorio}">
						<rich:ajaxValidator event="onblur" />
						<f:selectItems value="#{logradouroMB.cidadeOpts}"/>
					</rich:comboBox>
					</h:panelGroup>
				</h:panelGrid></fieldset>				
				<br />

				<h:panelGrid columns="2" width="100%" style="text-align:center;">
					<h:panelGroup>
						<a4j:commandButton value="#{msg.botaoSalvar}"
							action="#{instituicaoMB.save}" reRender="idInstituicaoMBForm, instituicaoList"
							style="text-align:center;" />
						<rich:spacer width="15px" />
						<a4j:commandButton value="#{msg.botaoAtualizar}"
							action="#{instituicaoMB.atualiza}" style="text-align:center;" reRender="idInstituicaoMBForm"/>
						<rich:spacer width="15px"/>
						<a4j:commandButton value="#{msg.botaoLimpar}"
							action="#{instituicaoMB.limpar}" reRender="idInstituicaoMBForm" style="text-align:center;" />
					</h:panelGroup>
				</h:panelGrid>
			</p:panel>
		</h:form>
		<br />
		
		<h:form>
		<p:panel>
			<a4j:commandButton reRender="idInstituicaoMBForm" value="#{msg.alterar}" action="#{instituicaoMB.listaToFormInstituicao}"/>
			<h:commandButton onclick="return confirm('Deseja excluir o registro?')" value="#{msg.excluir}" action="#{instituicaoMB.remove}" reRender="instituicaoList"/>
			<p:dataTable id="instituicaoList" var="instituicao" value="#{instituicaoMB.instituicaoList}" paginator="true" rows="6" 
				selection="#{instituicaoMB.instituicaoSelectedList}" selectionMode="multiple">

				<p:column filterBy="#{instituicao.nome}" sortBy="#{instituicao.nome}" width="300">
					<f:facet name="header">
						<h:outputText value="#{msg.nome}" />
					</f:facet>
					<h:outputText value="#{instituicao.nome}" />
				</p:column>
				
				<p:column filterBy="#{instituicao.unidade}" sortBy="#{instituicao.unidade}">
					<f:facet name="header">
						<h:outputText value="#{msg.unidade}" />
					</f:facet>
					<h:outputText value="#{instituicao.unidade}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="#{msg.telefoneEmp}" />
					</f:facet>
					<h:outputText value="#{instituicao.logradouro.telefoneEmpresa}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="#{msg.rua}" />
					</f:facet>
					<h:outputText value="#{instituicao.logradouro.rua}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="#{msg.bairro}" />
					</f:facet>
					<h:outputText value="#{instituicao.logradouro.bairro}" />
				</p:column>

				<p:column>
					<f:facet name="header">
						<h:outputText value="#{msg.bairro}" />
					</f:facet>
					<h:outputText value="#{instituicao.logradouro.cidade.nome}" />
				</p:column>
		
			</p:dataTable>
			
			<h:outputText value="#{msg.exportarTodosDados}" style="font-weight:bold"/>:
			<h:commandLink>
				<p:graphicImage value="/images/excel.png" style="border:0;"/>
				<p:dataExporter type="xls" target="instituicaoList" fileName="#{msg.instituicao}" />
			</h:commandLink>
			<h:commandLink>
				<p:graphicImage value="/images/pdf.png" style="border:0;"/>
				<p:dataExporter type="pdf" target="instituicaoList" fileName="#{msg.instituicao}"/>
			</h:commandLink><rich:spacer width="10px"/>
	
			<h:outputText value="#{msg.exportarDadosPagina}" style="font-weight:bold"/>:
			<h:commandLink>
				<p:graphicImage value="/images/excel.png" style="border:0;"/>
				<p:dataExporter type="xls" target="instituicaoList" fileName="#{msg.instituicao}" />
			</h:commandLink>
			<h:commandLink>
				<p:graphicImage value="/images/pdf.png" style="border:0;"/>
				<p:dataExporter type="pdf" target="instituicaoList" fileName="#{msg.instituicao}"/>
			</h:commandLink>
		</p:panel>
	</h:form>
		
</ui:composition>